//http://www.cnblogs.com/zongwan/archive/2010/06/18/1760389.html
package
{
	import com.ds.RectangleStruct;
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	import flash.utils.getTimer;
	
	import org.osmf.media.LoadableElementBase;
	
	[SWF(width=1250,height=650,frameRate=24)]
	public class ModuleMap extends Sprite
	{
		
		private var mapclass:Class;
		private var array:Array;
		
		private var mouse_sx:Number;
		private var mouse_sy:Number;
		private var mouse_ex:Number;
		private var mouse_ey:Number;
		private var flag:Boolean;
		private var _x:Number;
		private var _y:Number;
		private var _id:int;
		private var _count:int;
		
		private var loader:Loader = new Loader();
		private var mapid:TextField = new TextField();
		private var bigmap:Sprite = new Sprite();
		
		public function ModuleMap()
		{
			addChild(bigmap);
			
			var rect:Sprite = new Sprite();
			rect.graphics.beginFill(0x000000,0);
			rect.graphics.lineStyle(1);
			rect.graphics.drawRect(0,0,250,130);
			addChild(rect);
			rect.x = (stage.stageWidth - rect.width)/2;
			rect.y = (stage.stageHeight - rect.height)/2;
			
			mapid.width = 100;
			mapid.height = 30;
			mapid.x = (stage.stageWidth - mapid.width)/2;
			mapid.y = (stage.stageHeight - mapid.height)/2;
			
			RectangleStruct.row = 4;
			RectangleStruct.col = 5;
			init(8);
		}
		
		private function init(id:int):void
		{
			_id = id;
			array = RectangleStruct.getAreaID(_id);
			loadMap();
		}
		
		private function loadMap():void
		{
			/*var loaders:Loader = new Loader();
			loaders.load(new URLRequest("maps/map"+array[_count]+".jpg"));
			loaders.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);*/
		}
		
		private function completeHandler(e:Event):void
		{
			_count++;
			//trace(e.target is LoaderInfo);
			//e.target.scaleX = 0.2;
			//e.target.scaleY = 0.2;
			//bigmap.addChild(e.target as Loader);
			array.splice(0,1);
			if(array.length>0)
				loadMap();
		}
		
		private function downHandler(e:MouseEvent):void
		{
			mouse_sx = stage.mouseX;
			mouse_sy = stage.mouseY;
		}
		
		private function upHandler(e:MouseEvent):void
		{
			mouse_ex = stage.mouseX;
			mouse_ey = stage.mouseY;
			mouse();
		}
		
		private function mouse():void
		{
			_x = mouse_ex - mouse_sx;
			_y = mouse_ey - mouse_sy;
			//右上
			if(_x>0&&_y<0)
			{
				trace("右上");
			}
			//右下
			if(_x>0&&_y>0)
			{
				trace("右下");
			}
			//左下
			if(_x<0&&_y>0)
			{
				trace("左下");
			}
			//左上
			if(_x<0&&_y<0)
			{
				trace("左上");
			}
			//右平移
			if(_x>0&&_y==0)
			{
				trace("右平移");
			}
			//下平移
			if(_x==0&&_y>0)
			{
				trace("下平移");
			}
			//左平移
			if(_x<0&&_y==0)
			{
				trace("左平移");
			}
			//上平移
			if(_x==0&&_y<0)
			{
				trace("上平移");
			}
			
			bigmap.x += _x;
			bigmap.y += _y;
		}
		
		public function getRanta():void
		{
			var a:Sprite = new Sprite();
			
		}
	}
}